
package com.jf.cloud.product.feign;

import com.jf.cloud.api.product.feign.CategoryFeignClient;
import com.jf.cloud.common.product.vo.CategoryVO;
import com.jf.cloud.common.product.vo.ParentCategoryVO;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.product.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import io.swagger.v3.oas.annotations.Hidden;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author zz
 * @date 2020/12/23
 */
@RestController
@Hidden
public class CategoryFeignController implements CategoryFeignClient {

    @Autowired
    private CategoryService categoryService;

    @Override
    public ServerResponseEntity<List<Long>> listCategoryId(Long categoryId) {
        CategoryVO category = categoryService.getById(categoryId);
        List<Long> categoryIds = categoryService.listCategoryId( category.getParentId());
        return ServerResponseEntity.success(categoryIds);
    }

    @Override
    public ServerResponseEntity<CategoryVO> getByCategoryId(Long categoryId) {
        return ServerResponseEntity.success(categoryService.getById(categoryId));
    }

    @Override
    public ServerResponseEntity<String> getCategoryAllById(Long categoryId) {
        // 获取平台分类数据
        CategoryVO category = categoryService.getInfo(categoryId);
        List<ParentCategoryVO> categories = category.getCategories();
        //平台三级分类名称
        String threeCategory =  category.getCategoryLangList().get(0).getName();
        //平台二级分类名称
        String twoCategory = categories.get(1).getName();
        //平台一级分类名称
        String oneCategory = categories.get(0).getName();
        String categoryNames = oneCategory+"/"+twoCategory+"/"+threeCategory;
        return ServerResponseEntity.success(categoryNames);
    }

    @Override
    public ServerResponseEntity<List<CategoryVO>> getByCategoryIds(Set<Long> categoryIds) {
        return ServerResponseEntity.success(categoryService.listByCategoryIds(categoryIds));
    }

    @Override
    public ServerResponseEntity<List<Map<String,Object>>> listPrimaryCategoryId() {
        return ServerResponseEntity.success(categoryService.listPrimaryCategoryId());
    }

    @Override
    public ServerResponseEntity<List<Long>> listByPrimaryCategoryId(Long cateId) {
        return ServerResponseEntity.success(categoryService.listByPrimaryCategoryId(cateId));
    }


}
